package com.clkj.xiuzheng.controller.shangcheng;

import com.clkj.xiuzheng.pojo.common.Result;
import com.clkj.xiuzheng.pojo.common.StatusCode;
import com.clkj.xiuzheng.pojo.shangcheng.*;
import com.clkj.xiuzheng.service.shangcheng.MainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author yawang
 * @create 2024/05/13 11:42:18
 **/
@RestController
@RequestMapping(value = "/miniMain")
@CrossOrigin
@Api(value = "/miniMain", tags = {"A商城小程序首页"})
public class MainController {

    @Autowired
    private MainService mainService;

    @ApiOperation(value = "获取小程序首页")
    @PostMapping("/listMain")
    public Result listMain(Integer userId,Integer companyId) {
        try {
            Map map = mainService.listMain(userId, companyId);
            return new Result(true, StatusCode.OK, "查询成功",map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "查询失败");
        }
    }
    @ApiOperation(value = "小程序添加购物车")
    @PostMapping("/addCart")
    public Result addCart(ProductCart productCart) {
        try {
             mainService.addCart(productCart);
            return new Result(true, StatusCode.OK, "添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "添加失败");
        }
    }

    @ApiOperation(value = "小程序获取我的购物车")
    @PostMapping("/listCart")
    public Result listCart(Integer userId) {
        try {
            List<ProductCart> carts =  mainService.listCart(userId);
            return new Result(true, StatusCode.OK, "添加成功",carts);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "添加失败");
        }
    }

    @ApiOperation(value = "小程序删除购物车")
    @PostMapping("/deleteCart")
    public Result deleteCart(String cartIds) {
        try {
            mainService.deleteCart(cartIds);
            return new Result(true, StatusCode.OK, "删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "删除失败");
        }
    }

    @ApiOperation(value = "小程序获取钻石商城")
    @PostMapping("/listDiamond")
    public Result listDiamond() {
        try {
            List<SProduct> products =  mainService.listDiamond();
            return new Result(true, StatusCode.OK, "查询成功",products);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "添加失败");
        }
    }

    @ApiOperation(value = "小程序我的公告列表")
    @PostMapping("/listNotice")
    public Result listNotice(Integer userType,Integer companyId) {
        try {
            List<Notice> notices =  mainService.listNotice(userType,companyId);
            return new Result(true, StatusCode.OK, "查询成功",notices);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "添加失败");
        }
    }
    @ApiOperation(value = "小程序获取健康档案标签列表")
    @PostMapping("/listHealth")
    public Result listHealth() {
        try {
            List<ArchiveTag> healths =  mainService.listHealth();
            return new Result(true, StatusCode.OK, "查询成功",healths);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "添加失败");
        }
    }
    @ApiOperation(value = "小程序添加健康档案")
    @PostMapping("/addHealth")
    public Result addHealth(Integer userId,String tagIds) {
        try {
            mainService.addHealth(userId,tagIds);
            return new Result(true, StatusCode.OK, "添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "添加失败");
        }
    }
    @ApiOperation(value = "小程序获取健康数据")
    @PostMapping("/getHealth")
    public Result getHealth(Integer userId) {
        try {
            List<ArchiveTag> healths =  mainService.getHealth(userId);
            return new Result(true, StatusCode.OK, "查询成功",healths);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "添加失败");
        }
    } @ApiOperation(value = "小程序推广员获取我的推广用户列表")
    @PostMapping("/operatorGetUser")
    public Result operatorGetUser(Integer userId) {
        try {
            List<SUser> healths =  mainService.operatorGetUser(userId);
            return new Result(true, StatusCode.OK, "查询成功",healths);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "添加失败");
        }
    }

}
